<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * 数据组装类
 */

class Assembly
{
    protected $ci;

    public function __construct()
    {
        $this->ci =& get_instance();
    }

    /**
     * 组装数组
     * @param  array $data 传入数组， 必须有 id pid
     * @return array       [description]
     */
    public function data($data,$pid = 0){
        $res_array = [];
        foreach($data as $k => $v){
            if($v['pid'] == $pid){
                $v['tree'] = $this->data($data,$v['id']);
                $res_array[] = $v;
                unset($data[$k]);
            }
        }
        return $res_array;
    }

}